package com.mtable.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mtable.base.BaseServiceImpl;
import com.mtable.dao.MUserDao;
import com.mtable.entity.MUser;
import com.mtable.service.MUserService;

@Service
public class MUserServiceImpl extends BaseServiceImpl<MUser> implements MUserService{
	@Autowired
	public MUserServiceImpl(MUserDao mUserDao){
		super(mUserDao);
	}
	
	@Autowired
	private MUserDao mUserDao;
	public static int USERNAME_NOT_FOUND = 1;
	public static int PASSWORD_ERROR = 2;
	public static int ALL_RIGHT = 4;
	
	public int login(String username ,String password){
		List<MUser> userList = mUserDao.findByProperty("loginName", username);
		if(userList==null || userList.size()==0){
			return USERNAME_NOT_FOUND;
		}else{
			MUser muser = userList.get(0);
			if(password.equals(muser.getPassword())){
				
				return ALL_RIGHT;
			}else{
				return PASSWORD_ERROR;
			}
		}
	}

}
